<template>
  <div class="login-container">
    <div class="login-form">
      <h2>用户登录</h2>
      <div class="form-group">
        <label>账号:</label>
        <input type="text" v-model="username" placeholder="请输入账号">
      </div>
      <div class="form-group">
        <label>密码:</label>
        <input type="password" v-model="password" placeholder="请输入密码" @keyup.enter="handleLogin">
      </div>
      <button @click="handleLogin">登录</button>
    </div>
  </div>
</template>

<script>
import { ref } from 'vue'

export default {
  name: 'LoginPage',
  emits: ['login'],
  setup(props, { emit }) {
    const username = ref('')
    const password = ref('')

    const handleLogin = () => {
      if (username.value && password.value) {
        emit('login', username.value, password.value)
      } else {
        alert('请输入账号和密码')
      }
    }

    return {
      username,
      password,
      handleLogin
    }
  }
}
</script>

<style scoped>
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 100%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-form {
  background: white;
  padding: 2rem;
  border-radius: 10px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  width: 350px;
}

.login-form h2 {
  text-align: center;
  margin-bottom: 1.5rem;
  color: #333;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  color: #333;
  font-weight: bold;
}

.form-group input {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 1rem;
  box-sizing: border-box;
}

.form-group input:focus {
  outline: none;
  border-color: #667eea;
}

.login-form button {
  width: 100%;
  padding: 0.75rem;
  background-color: #667eea;
  color: white;
  border: none;
  border-radius: 5px;
  font-size: 1rem;
  cursor: pointer;
  margin-top: 1rem;
}

.login-form button:hover {
  background-color: #5a6fd8;
}
</style>